<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="common/common_head :: commonHeader('修改密码')"/>
</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox-content">

        <div class="row">
            <div class="col-sm-6">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">

                        <form class="form-horizontal">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">用户名：</label>
                                <div style="display:inline-block;width: 76.6%" class="col-sm-8">
                                    <input id="username" readonly="readonly" type="text" placeholder="用户名" class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">原密码：</label>

                                <div style="display:inline-block;width: 76.6%" class="col-sm-8">
                                    <input id="password" type="password" placeholder="原密码" class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">新密码：</label>
                                <div style="display:inline-block;width: 76.6%" class="col-sm-8">
                                    <input id="newPassword" maxlength="12" minlength="6"  type="password" placeholder="新密码" class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-3 col-sm-8" style="margin-left: 85px">
                                    <button class="btn btn-primary" type="button" onclick="updatePwd()">保 存</button>
                                    <button class="btn btn-primary" type="button" onclick="Dialog.closeFrame(window.name)">取
                                        消</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>

<script type="text/javascript">
    $(document).ready(function () {
        Page.ajaxPOST(ctxPath + "/sys/user/info", null, function (res) {
            $("#username").val(res.result.username);
        })
    })

    function updatePwd() {
        if($("#newPassword").val().trim().length<6){
            Dialog.errorMsg("新密码不能小于六位！");
            return;
        }

        Page.ajaxPOST(ctxPath+"/sys/user/password",{'password': $("#password").val(),
            'newPassword':$("#newPassword").val().trim()},
            function (res) {
                Dialog.msg("操作成功", function () {
                    Dialog.closeFrame(window.name);
                });

            }
        )
    }
</script>

</body>
</html>
